def split_file(file_path, lines_per_file):
    file_counter = 1
    with open(file_path, 'r', encoding='utf-8') as file:
        lines = []
        for i, line in enumerate(file):
            lines.append(line)
            if (i + 1) % lines_per_file == 0:
                output_file = f"{file_path}_part{file_counter}.txt"
                with open(output_file, 'w', encoding='utf-8') as output:
                    output.writelines(lines)
                lines = []
                file_counter += 1
        # 写入剩余的行
        if lines:
            output_file = f"{file_path}_part{file_counter}.txt"
            with open(output_file, 'w', encoding='utf-8') as output:
                output.writelines(lines)

# 使用方法
split_file(r'/www/project/one/claude_api/logs/uwsgi.log', 1000)  # 每个小文件包含 10000 行
